import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Button, ConfigProvider, Table } from 'antd';
import zhCN from 'antd/es/locale-provider/zh_CN';
import style from './style.less';

class TableC extends Component {
  // props默认值
  static defaultProps = {
    columns: [],
    dataSource: [],
    loading: false,
    total: 0, // 数据总量默认为0
    defaultCurrent: 1, // 默认当前页码为1
    current: 1,
    pageSize: 20, // 默认一页总量为20
    onChange: () => {}, // 页码改变的回调，参数是改变后的页码及每页条数
    onShowSizeChange: () => {}, // pageSize 变化的回调
    rowKey: 'id',
    page: true,
    showSizeChanger: true,
    showQuickJumper: false,
    size: '',
    defineStyle: '',
  };

  render() {
    const {
      columns,
      dataSource,
      loading,
      total,
      defaultCurrent,
      current,
      pageSize,
      onChange,
      onShowSizeChange,
      scroll,
      rowKey,
      page,
      pagination,
      showQuickJumper,
      showSizeChanger,
      size,
      defineStyle,
    } = this.props;
    return (
      <ConfigProvider locale={zhCN}>
        <div className={defineStyle !== '' ? defineStyle : style.tableC}>
          <Table columns={columns} dataSource={dataSource} loading={loading} onChange={onChange} rowKey={rowKey} pagination={pagination} scroll={scroll} />
        </div>
      </ConfigProvider>
    );
  }
}

// props类型
TableC.propsTypes = {
  columns: PropTypes.array, // 列信息
  dataSource: PropTypes.array, // 数据源
  loading: PropTypes.bool, // 加载中状态
  total: PropTypes.number, // 数据总量
  defaultCurrent: PropTypes.number, // 当前页码
  pageSize: PropTypes.number, // 一页数据量
  onChange: PropTypes.func, // 页码改变的回调，参数是改变后的页码及每页条数
  onShowSizeChange: PropTypes.func, // pageSize 变化的回调
  rowKey: PropTypes.string,
  showSizeChanger: PropTypes.bool,
  showQuickJumper: PropTypes.bool,
  size: PropTypes.string, //分页器属性
};

export default TableC;
